<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
    
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>
</head>
<body>

  <div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
      <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
          <li class="layui-this"><B>待我审批</B></li>
        </ul>
      </div>
      <div class="layui-card-body">
      	<!-- 数据表单 -->
        <table id="LAY-public-process-manage" lay-filter="LAY-public-process-manage"></table>
      </div>
    </div>
    <div class="layui-card">
      <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
          <li class="layui-this"><B>公司公告</B></li>
        </ul>
      </div>
      <div class="layui-card-body">
      	<div style="padding-bottom: 10px;">
          	<button class="layui-btn layuiadmin-btn-admin layui-btn-sm" data-type="add">
          	 <i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>全部已读
          	</button>
        </div>
      	<!-- 数据表单 -->
        <table id="LAY-notice-manage" lay-filter="LAY-notice-manage"></table>
      </div>
    </div>
  </div>
  <script>
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;
    
    // 表单
    table.render({
      elem: '#LAY-public-process-manage'
      ,url: basePath + '/flowProcess/queryPending' //请求数据接口
      ,cols: [[
         {field: 'startTime', title: '发起时间',width:170, templet: function(d){
  		 	  return layui.util.toDateString(d.startTime,"yyyy-MM-dd HH:mm:ss");
	  	  }
	     }
        ,{field: 'startOrgName', title: '发起部门', templet: function(d){
		 	  return d.startOrgName + "—" + d.startDeptName;
	  	  }
         }
        ,{field: 'startRealName', title: '发起人',width:150}
        ,{field: 'templateName', title: '流程名称'}
        ,{field: 'addTime', title: '上节点处理时间', width:170,templet: function(d){
    		  return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
	      }
	     }
        ,{title: '操作',  align:'center',width:140, templet: function(d){
        	var optStr = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="toDispatch"><i class="layui-icon layui-icon-release"></i>去审批</a>';
  		  	return optStr;
        	}
        }
      ]]
      ,page: true
      ,limit: 5
      ,limits:[5,10,20,30,50]
      ,done: function () {$(window).resize();}
    });
    
 	// 表单
    table.render({
      elem: '#LAY-notice-manage'
      ,url: basePath + '/notice/queryData' //请求数据接口
      ,cols: [[
        {field: 'types', title: '公告类型', width:130, templet: function (d) {
	        	if(d.read){
	   				return '<span class="layui-badge-dot" style="position: relative; top: 0px; left: 0px; visibility:hidden"></span> <button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-primary">'+d.types+'</button>';
	   			}else{
	   				return '<span class="layui-badge-dot" style="position: relative; top: 0px; left: 0px;"></span> <button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-primary">'+d.types+'</button>';
	   			}
	    	}
        }
        ,{field: 'addTime', title: '发布时间', width:170, templet: function(d){
    		  return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
    		}
        }
        ,{field: 'title', title: '标题'}
        ,{field: 'summary', title: '摘要'}
      ]]
      ,page: true
      ,limit: 5
      ,limits:[5,10,20,30,50]
      ,done: function () {$(window).resize();}
    });
    
    // 监听操作列
    table.on('tool(LAY-public-process-manage)', function(obj){
    	var data = obj.data;
      	if(obj.event === 'toDispatch'){
    	  	parent.layui.index.openTabsPage(basePath + '/flowProcess/toDispatch?processId='+data.processId, data.templateName+ ' > 审批');
      	}
    });
    
  	//监听行单击事件
    table.on('row(LAY-notice-manage)', function(obj){
      	parent.layui.index.openTabsPage(basePath + '/notice/queryById?id='+obj.data.id,'公司公告 > 详情');
     	// 刷新首页 
		var iframe = window.parent.layui.admin.tabsBody(0).find(".layadmin-iframe");
		iframe[0].contentWindow.location.reload(true);
    });
    
 	// 按钮事件
    var active = {
    	add: function(){
    		layer.confirm('确定全部已读？',{icon:3, title :'提示'}, function(index){
      			$.ajax({
						type : 'post',
						url : basePath + '/notice/updateReadStatus',
						success:function(result){
							if(result.success){
								table.reload('LAY-notice-manage'); //数据刷新
								layer.close(index);
							}else{
								layer.msg(result.msg,{icon: 7});
				  			}
						}
					});
      		}); 
      }
    } 
    
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
</body>
</html>